package com.example.administrator.printoutindemo.mvp.ui.activity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.di.component.DaggerMainNengLiangEComponent;
import com.example.administrator.printoutindemo.di.module.MainNengLiangEModule;
import com.example.administrator.printoutindemo.mvp.contract.MainNengLiangEContract;
import com.example.administrator.printoutindemo.mvp.presenter.MainNengLiangEPresenter;
import com.example.administrator.printoutindemo.mvp.ui.adapter.ZuiXinXiaoXiAdapter;
import com.example.administrator.printoutindemo.mvp.ui.entity.AppIndexCount;
import com.example.administrator.printoutindemo.mvp.ui.entity.MainNengLiangE;
import com.example.administrator.printoutindemo.mvp.ui.entity.ZuiXinXiaoXi;
import com.example.administrator.printoutindemo.utils.GlideImageLoader;
import com.example.administrator.printoutindemo.view.LineGridView;
import com.google.gson.Gson;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.BaseConstants;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.redking.util.InitX5;
import com.xiaoxing.gifloadingview.LoadingDialogUtil;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.jessyan.armscomponent.commonres.utils.ToolbarUtils;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;
import me.jessyan.armscomponent.commonsdk.utils.Utils;
import pub.devrel.easypermissions.EasyPermissions;

import static com.jess.arms.utils.Preconditions.checkNotNull;


@Route(path = RouterHub.ACTIVITY_MAIN_NENG_LIANG_E)
public class MainNengLiangEActivity extends BaseActivity<MainNengLiangEPresenter> implements MainNengLiangEContract.View, EasyPermissions.PermissionCallbacks {


    private static final int LOGINSUCCESS = 0;
    private static final int NETWORKERROR = 2;
    private static final int SYSERROR = 3;
    @BindView(R.id.tv_dai_shen_he)
    TextView tvDaiShenHe;
    @BindView(R.id.tv_dai_ru_ku)
    TextView tvDaiRuKu;
    @BindView(R.id.tv_dai_chu_ku)
    TextView tvDaiChuKu;
    @BindView(R.id.convenientBanner)
    Banner banner;
    @BindView(R.id.gridview)
    LineGridView gridView;
    @BindView(R.id.btnRight)
    ImageView mBtnRight;
    private String SYSException = "";
    private AppIndexCount mAppIndexCount;
    @SuppressLint("HandlerLeak")
    private final Handler hanlder = new Handler() {
        public void handleMessage(Message msg) {
            LoadingDialogUtil.dismissDialog();

            switch (msg.what) {
                case LOGINSUCCESS:

                    if (mAppIndexCount != null) {
                        tvDaiShenHe.setText(String.valueOf(mAppIndexCount.getCheckCount()));
                        tvDaiRuKu.setText(String.valueOf(mAppIndexCount.getInstoreCount()));
                        tvDaiChuKu.setText(String.valueOf(mAppIndexCount.getOutstoreCount()));
                    }

                    break;

                case NETWORKERROR:

                    Toast.makeText(getContext(), "网络或系统异常!", Toast.LENGTH_LONG).show();
                    break;
                case SYSERROR:

                    Toast.makeText(getContext(), "系统异常!", Toast.LENGTH_LONG).show();
                    break;

                default:
                    break;
            }

        }
    };
    private String[] permissions = {
            android.Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE};
    private String[] permissionsLocation = {
            Manifest.permission.ACCESS_COARSE_LOCATION};
    private View.OnClickListener mRightListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mSharedPreferencesHelper.removeString("user");
            mSharedPreferencesHelper.removeString("name1");
            mSharedPreferencesHelper.removeString("password1");
            mSharedPreferencesHelper.removeString(BaseConstants.ROLE_ID);
            mSharedPreferencesHelper.putBoolean(BaseConstants.IS_LOGIN, false);

            ArmsUtils.makeText(MainNengLiangEActivity.this, "退出成功");

            Utils.navigation(getContext(), RouterHub.APP_LOGINACTIVITY);

            finish();
        }
    };

    @Override
    public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {

        ArmsUtils.makeText(this, "相关权限获取成功");
    }

    @Override
    public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
        ArmsUtils.makeText(this, "请同意相关权限，否则功能无法使用");

    }

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerMainNengLiangEComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .mainNengLiangEModule(new MainNengLiangEModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_main_neng_liang_e; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        Toolbar toolbar = ToolbarUtils.initToolbarTitleNoBack(this, "主页");

//        toolbar.setNavigationIcon(R.drawable.icon_qian_dao);
//        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (getLocationPermission())
//                    toQianDao(RouterHub.ACTIVITY_QIAN_DAO);
//            }
//        });
        initBtnRight();
//        getMainNengLiangEData();
//        ininBanner();
        InitX5.initX5(this);

        initGridView();
        initRecyclerView();

//        if (TextUtils.isEmpty(mSharedPreferencesHelper.getString(BaseConstants.SHE_ZHI_IP)) && TextUtils.isEmpty(mSharedPreferencesHelper.getString(BaseConstants.SHE_ZHI_PORT))) {
//            mSharedPreferencesHelper.putString(BaseConstants.SHE_ZHI_IP, BaseConstants.SHE_ZHI_IP_VALUE);
//            mSharedPreferencesHelper.putString(BaseConstants.SHE_ZHI_PORT, BaseConstants.SHE_ZHI_PORT_VALUE);
//        }


    }

    private void initBtnRight() {
        mBtnRight.setOnClickListener(mRightListener);
        mBtnRight.setImageDrawable(getResources().getDrawable(R.drawable.icon_logout));
    }

    private void initGridView() {
        List<Map<String, Object>> dataList;
        SimpleAdapter mSimpleAdapter;
        //图标
        int[] icno = {R.drawable.icon_shen_qing, R.drawable.icon_shen_he, R.drawable.icon_dai_shen_pi, R.drawable.icon_dai_ling_liao, R.drawable.icon_shan_dian, R.drawable.icon_ru_ku, R.drawable.icon_ru_ku_cheng_gong, R.drawable.icon_chu_ku, R.drawable.icon_scan_wu_liao_xiang_qing, R.drawable.icon_ku_cun, R.drawable.icon_chu_ku_qing_kuang, R.drawable.icon_ru_ku_qing_kuang};
        //图标下的文字
        String[] name = {"领料申请", "申请记录", "待审批", "待领料", "待审核", "待入库", "入库记录", "待出库", "物料详情", "库存", "出库情况", "入库情况"};

        String roleId = mSharedPreferencesHelper.getString(BaseConstants.ROLE_NAME);

        if (roleId.equals(BaseConstants.LoginRole.CAI_LIAO_YUAN.getValue())) {

            if (mSharedPreferencesHelper.getString(BaseConstants.COMPANY).equals(BaseConstants.Company.COMPANY_LIN_YI.getValue())) {//判断是不是临沂的材料员登录的
                //申请人
                icno = new int[]{R.drawable.icon_shen_qing, R.drawable.icon_shen_he, R.drawable.icon_dai_shen_pi, R.drawable.icon_dai_ling_liao, R.drawable.icon_door};
                name = new String[]{"领料申请", "申请记录", "待审批", "待领料", "开关门"};

            } else {
                //申请人
                icno = new int[]{R.drawable.icon_shen_qing, R.drawable.icon_shen_he, R.drawable.icon_dai_shen_pi, R.drawable.icon_dai_ling_liao};
                name = new String[]{"领料申请", "申请记录", "待审批", "待领料"};

            }
        }

        if (roleId.equals(BaseConstants.LoginRole.SHEN_HE_REN.getValue())) {

            //审核人
            icno = new int[]{R.drawable.icon_shan_dian};

            name = new String[]{"待审核"};
        }
        if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {

            //仓管员
            icno = new int[]{R.drawable.icon_ru_ku, R.drawable.icon_ru_ku_cheng_gong, R.drawable.icon_chu_ku, R.drawable.icon_ru_ku_qing_kuang, R.drawable.icon_scan_wu_liao_xiang_qing, R.drawable.icon_ku_cun, R.drawable.icon_chu_ku, R.drawable.icon_ru_ku_qing_kuang, R.drawable.icon_ru_ku, R.drawable.icon_ru_ku, R.drawable.icon_cang_wei_lie_biao, R.drawable.icon_sao_miao_cang_wei_ma};//, R.drawable.icon_ru_ku
            name = new String[]{"待入库", "入库记录", "待出库", "出库情况", "扫描出库", "库存", "抽检出库", "抽检退库", "物料详情", "扫描分码", "仓位列表", "扫描仓位码"};//, "质检完成入库"
        }

        if (roleId.equals(BaseConstants.LoginRole.GONG_QI_JU.getValue())) {

            //工器具
            icno = new int[]{R.drawable.icon_ru_ku, R.drawable.icon_ru_ku_cheng_gong, R.drawable.icon_chu_ku, R.drawable.icon_ru_ku_qing_kuang, R.drawable.icon_ku_cun, R.drawable.icon_scan_wu_liao_xiang_qing, R.drawable.icon_ku_cun};
            name = new String[]{"入库", "申请出库", "出库操作", "归还", "库存列表", "应用追踪", "应急出库"};
        }
        if (roleId.equals(BaseConstants.LoginRole.LING_DAO.getValue())) {

            //领导
            icno = new int[]{R.drawable.icon_ku_cun, R.drawable.icon_chu_ku_qing_kuang
                    , R.drawable.icon_ru_ku_qing_kuang, R.drawable.icon_zhou_bao
                    , R.drawable.icon_sheng_chan_diao_du, R.drawable.icon_zhi_hui_cang_chu
                    , R.drawable.icon_shan_dian_pei_song, R.drawable.icon_zhuan_ye_an_zhuang
            };
            name = new String[]{"库存", "出库情况", "入库情况", "周报", "生产调度", "智慧仓储", "闪电配送", "专业安装"};
        }
        if (roleId.equals(BaseConstants.LoginRole.PAN_DIAN_YUAN.getValue())) {

            //盘点员
            icno = new int[]{R.drawable.icon_pan_dian};
            name = new String[]{"盘点"};
        }

        dataList = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < icno.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("img", icno[i]);
            map.put("text", name[i]);
            dataList.add(map);
        }

        String[] from = {"img", "text"};

        int[] to = {R.id.home_item_product_img, R.id.tv_text};

        mSimpleAdapter = new SimpleAdapter(this, dataList, R.layout.item_main, from, to);

        gridView.setAdapter(mSimpleAdapter);

//        setGridViewMatchParent(gridView);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                if (!mSharedPreferencesHelper.getBoolean(BaseConstants.IS_LOGIN)) {
                    ArmsUtils.makeText(getContext(), "请先登录");
                    Utils.navigation(getContext(), RouterHub.APP_LOGINACTIVITY);
                    return;
                }

                String roleId = mSharedPreferencesHelper.getString(BaseConstants.ROLE_NAME);

                switchShenQingRen(arg2, roleId);
            }
        });
    }

    private void initRecyclerView() {
        RecyclerView recyclerView = findViewById(R.id.recyclerView);
        ZuiXinXiaoXiAdapter mAdapter = new ZuiXinXiaoXiAdapter(this, loadModels());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

//                ArmsUtils.makeText(getContext(), "position=0" + position);
            }
        });
    }

    private void switchShenQingRen(int arg2, String roleId) {

        if (roleId.equals(BaseConstants.LoginRole.CAI_LIAO_YUAN.getValue())) {
            switch (arg2) {
                case 0:
                    if (roleId.equals(BaseConstants.LoginRole.CAI_LIAO_YUAN.getValue())) {
                        Bundle bundle = new Bundle();
                        bundle.putString("ling_liao_lei_xing", "1");
                        Utils.navigation(getContext(), RouterHub.APP_STORESUBMITPROJECT1ACTIVITY, bundle);
                    } else {
                        noViewPermission();
                    }

                    break;
                case 1:
                    if (roleId.equals(BaseConstants.LoginRole.CAI_LIAO_YUAN.getValue())) {
                        Utils.navigation(getContext(), RouterHub.APP_STORE_SUBMIT_PROJECT_LIST_ACTIVITY);
                    } else {
                        noViewPermission();
                    }
                    break;
                case 2:
                    if (roleId.equals(BaseConstants.LoginRole.CAI_LIAO_YUAN.getValue())) {
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_DAI_SHEN_PI);
                    } else {
                        noViewPermission();
                    }
                    break;
                case 3:
                    if (roleId.equals(BaseConstants.LoginRole.CAI_LIAO_YUAN.getValue())) {
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_DAI_LING_LIAO);
                    } else {
                        noViewPermission();
                    }
                    break;
                case 4:
                    if (isLinYi()) {

                        Utils.navigation(getContext(), RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_ACTIVITY_LIN_YI_KAI_GUAN_MEN);
                    } else {
                        Bundle bundle = new Bundle();
                        bundle.putString("ling_liao_lei_xing", "2");
                        Utils.navigation(getContext(), RouterHub.APP_STORESUBMITPROJECT1ACTIVITY, bundle);
                    }
                    break;

            }
        } else if (roleId.equals(BaseConstants.LoginRole.SHEN_HE_REN.getValue())) {
            switch (arg2) {

                case 0:
                    if (roleId.equals(BaseConstants.LoginRole.SHEN_HE_REN.getValue())) {
                        Utils.navigation(getContext(), RouterHub.APP_STORE_OUT_STORAGE_CHECK_LIST_1_ACTIVITY);
                    } else {
                        noViewPermission();
                    }
                    break;

            }
        } else if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
            switch (arg2) {

                case 0:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_RU_KU);
                    } else {
                        noViewPermission();
                    }

                    break;
                case 1:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_RU_KU_CHENG_GONG_JI_LU);
                    } else {
                        noViewPermission();
                    }
                    break;
                case 2:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_CHU_KU);
                    } else {
                        noViewPermission();
                    }
                    break;
                case 3:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
                        Bundle bundle = new Bundle();
                        bundle.putString("chu_ku_qing_kuang_type", "cgy");
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_CHU_KU_QING_KUANG, bundle);
                    } else {
                        noViewPermission();
                    }
                    break;
                case 4:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
                        Bundle bundle = new Bundle();
                        bundle.putString("type", "1");
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_SAO_MIAO_CHA_KAN_XIANG_QING, bundle);
                    } else {
                        noViewPermission();
                    }
                    break;

                case 5:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_KU_CUN);
                    } else {
                        noViewPermission();
                    }

                    break;
                case 6:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
//                        Utils.navigation(getContext(), RouterHub.ACTIVITY_RU_KU_ZHI_JIAN_WAN_CHENG);
                        Utils.navigation(this, RouterHub.ZHI_NENG_HUA_CANG_KU_ZHI_JIAN_ACTIVITY_CHOU_JIAN_CHU_KU_LIE_BIAO);
                    } else {
                        noViewPermission();
                    }


                    break;
                case 7:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
//                        Utils.navigation(getContext(), RouterHub.ACTIVITY_RU_KU_ZHI_JIAN_WAN_CHENG);
                        Utils.navigation(this, RouterHub.ZHI_NENG_HUA_CANG_KU_ZHI_JIAN_ACTIVITY_CHOU_JIAN_TUI_KU_LIE_BIAO);
                    } else {
                        noViewPermission();
                    }

                    break;
                case 8:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
                        Bundle bundle = new Bundle();
                        bundle.putString("type", "2");
                        Utils.navigation(this, RouterHub.ACTIVITY_SAO_MIAO_CHA_KAN_XIANG_QING, bundle);
                    } else {
                        noViewPermission();
                    }

                    break;
                case 9:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
                        Utils.navigation(this, RouterHub.ZHI_NENG_HUA_CANG_KU_ACTIVITY_SAO_MIAO_FEN_MA);
                    } else {
                        noViewPermission();
                    }

                    break;
                case 10:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
                        Utils.navigation(this, RouterHub.ACTIVITY_CANG_WEI_LIE_BIAO);
                    } else {
                        noViewPermission();
                    }

                    break;
                case 11:
                    if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
                        Utils.navigation(this, RouterHub.ACTIVITY_SAO_MIAO_CANG_WEI_MA);
                    } else {
                        noViewPermission();
                    }

                    break;

            }
        } else if (roleId.equals(BaseConstants.LoginRole.GONG_QI_JU.getValue())) {
            switch (arg2) {
                case 0:
                    Utils.navigation(getContext(), RouterHub.GONGQIJU_LIAOCHENG_ACTIVITY_LIAO_CHENG_GONG_QI_JU_RU_KU);

                    break;
                case 1:
                    Utils.navigation(getContext(), RouterHub.GONGQIJU_LIAOCHENG_ACTIVITY_LIAO_CHENG_GONG_QI_JU_SHEN_QING_CHU_KU);

                    break;
                case 2:
                    Utils.navigation(getContext(), RouterHub.GONGQIJU_LIAOCHENG_ACTIVITY_LIAO_CHENG_GONG_QI_JU_CHU_KU_CAO_ZUO);

                    break;
                case 3:
                    Utils.navigation(getContext(), RouterHub.GONGQIJU_LIAOCHENG_ACTIVITY_LIAO_CHENG_GONG_QI_JU_GUI_HUAN);
                    break;
                case 4:
                    Utils.navigation(getContext(), RouterHub.GONGQIJU_LIAOCHENG_ACTIVITY_LIAO_CHENG_GONG_QI_JU_KU_CUN_LIE_BIAO);
                    break;
                case 5:
                    Utils.navigation(getContext(), RouterHub.GONGQIJU_LIAOCHENG_ACTIVITY_LIAO_CHENG_GONG_QI_JU_PAI_ZHAO_ZHUI_ZONG);
                    break;
                case 6:
                    Utils.navigation(getContext(), RouterHub.GONGQIJU_LIAOCHENG_ACTIVITY_LIAO_CHENG_GONG_QI_JU_YING_JI_CHU_KU);
                    break;

            }
        } else if (roleId.equals(BaseConstants.LoginRole.LING_DAO.getValue())) {
            switch (arg2) {
                case 0:
                    if (roleId.equals(BaseConstants.LoginRole.LING_DAO.getValue())) {
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_KU_CUN);
                    } else {
                        noViewPermission();
                    }

                    break;
                case 1:
                    if (roleId.equals(BaseConstants.LoginRole.LING_DAO.getValue())) {
                        Bundle bundle = new Bundle();
                        bundle.putString("chu_ku_qing_kuang_type", "ld");
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_CHU_KU_QING_KUANG, bundle);
                    } else {
                        noViewPermission();
                    }

                    break;
                case 2:
                    if (roleId.equals(BaseConstants.LoginRole.LING_DAO.getValue())) {
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_RU_KU_QING_KUANG);
                    } else {
                        noViewPermission();
                    }
                    break;
                case 3:
                    if (getPermission()) {

                        if (roleId.equals(BaseConstants.LoginRole.LING_DAO.getValue())) {
                            Utils.navigation(getContext(), RouterHub.ACTIVITY_ZHOU_BAO);
                        } else {
                            noViewPermission();
                        }
                    }
                    break;

                case 4:
                    if (getPermission()) {

                        if (roleId.equals(BaseConstants.LoginRole.LING_DAO.getValue())) {
                            Utils.navigation(getContext(), RouterHub.ACTIVITY_SHENG_CHAN_DIAO_DU);
                        } else {
                            noViewPermission();
                        }
                    }
                    break;
                case 5:
                    if (getPermission()) {

                        if (roleId.equals(BaseConstants.LoginRole.LING_DAO.getValue())) {
                            Utils.navigation(getContext(), RouterHub.ACTIVITY_ZHI_HUI_CANG_CHU);
                        } else {
                            noViewPermission();
                        }
                    }
                    break;

                case 6:
                    if (getPermission()) {

                        if (roleId.equals(BaseConstants.LoginRole.LING_DAO.getValue())) {
                            Utils.navigation(getContext(), RouterHub.ACTIVITY_SHAN_DIAN_PEI_SONG);
                        } else {
                            noViewPermission();
                        }
                    }
                    break;

                case 7:
                    if (getPermission()) {

                        if (roleId.equals(BaseConstants.LoginRole.LING_DAO.getValue())) {
                            Utils.navigation(getContext(), RouterHub.ACTIVITY_ZHUAN_YE_AN_ZHUANG);
                        } else {
                            noViewPermission();
                        }
                    }

                    break;
            }
        } else if (roleId.equals(BaseConstants.LoginRole.PAN_DIAN_YUAN.getValue())) {
            switch (arg2) {
                case 0:
                    if (roleId.equals(BaseConstants.LoginRole.PAN_DIAN_YUAN.getValue())) {
                        Utils.navigation(getContext(), RouterHub.ACTIVITY_PAN_DIAN);
                    } else {
                        noViewPermission();
                    }

                    break;

            }
        } else {
            noViewPermission();
        }

    }

    private List<ZuiXinXiaoXi.DataBean> loadModels() {
        List<ZuiXinXiaoXi.DataBean> addressLists = new ArrayList<>();


        ZuiXinXiaoXi.DataBean addressList = new ZuiXinXiaoXi.DataBean();
        addressList.setName("组织签署承诺书的通知");
        addressList.setPublicTime("2018-03-16");
        addressLists.add(addressList);

        ZuiXinXiaoXi.DataBean addressList1 = new ZuiXinXiaoXi.DataBean();
        addressList1.setName("关于物资公司增值税专用发票开票信息变更的通知");
        addressList1.setPublicTime("2017-11-23");
        addressLists.add(addressList1);

        ZuiXinXiaoXi.DataBean addressList2 = new ZuiXinXiaoXi.DataBean();
        addressList2.setName("关于协议库存合同支付比例调整的通知");
        addressList2.setPublicTime("2019-09-16");
        addressLists.add(addressList2);

        ZuiXinXiaoXi.DataBean addressList3 = new ZuiXinXiaoXi.DataBean();
        addressList3.setName("组织签署承诺书的通知");
        addressList3.setPublicTime("2018-03-16");
        addressLists.add(addressList3);


        return addressLists;
    }

    private void noViewPermission() {
        ArmsUtils.makeText(this, "对不起，您没有权限查看！");
    }

    private boolean getPermission() {
        if (EasyPermissions.hasPermissions(this, permissions)) {

            return true;
        } else {

            EasyPermissions.requestPermissions(this, "需要获取文件使用权限", 103, permissions);
            return false;
        }

    }

    private boolean getLocationPermission() {
        if (EasyPermissions.hasPermissions(this, permissionsLocation)) {

            return true;
        } else {

            EasyPermissions.requestPermissions(this, "需要获取定位权限", 104, permissionsLocation);
            return false;
        }

    }


    private void ininBanner() {
        List<Integer> listImages = new ArrayList<>();
        List<String> listTitles = new ArrayList<>();

        listImages.add(R.drawable.banner_001);
        listImages.add(R.drawable.banner_001);
        listImages.add(R.drawable.banner_001);
        listImages.add(R.drawable.banner_001);
        listImages.add(R.drawable.banner_001);


        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        banner.setIndicatorGravity(BannerConfig.RIGHT);
        banner.setImageLoader(new GlideImageLoader());
        banner.setImages(listImages);
        banner.setDelayTime(5000);
        banner.start();
    }

    @OnClick({R.id.ll_dai_shen_he, R.id.ll_dai_ru_ku, R.id.ll_dai_chu_ku})
    public void onViewClicked(View view) {
        if (!mSharedPreferencesHelper.getBoolean(BaseConstants.IS_LOGIN)) {
            ArmsUtils.makeText(getContext(), "请先登录");
            Utils.navigation(getContext(), RouterHub.APP_LOGINACTIVITY);
            return;
        }

        String roleId = mSharedPreferencesHelper.getString(BaseConstants.ROLE_NAME);
        switch (view.getId()) {
            case R.id.ll_dai_shen_he:
                if (roleId.equals(BaseConstants.LoginRole.SHEN_HE_REN.getValue())) {
                    Utils.navigation(getContext(), RouterHub.APP_STORE_OUT_STORAGE_CHECK_LIST_1_ACTIVITY);
                } else {
                    noViewPermission();
                }
                break;
            case R.id.ll_dai_ru_ku:
                if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {

                    Utils.navigation(getContext(), RouterHub.ACTIVITY_RU_KU);
                } else {
                    noViewPermission();
                }
                break;
            case R.id.ll_dai_chu_ku:
                if (roleId.equals(BaseConstants.LoginRole.CANG_GUAN_YUAN.getValue())) {
                    Utils.navigation(getContext(), RouterHub.ACTIVITY_CHU_KU);
                } else {
                    noViewPermission();
                }
                break;
        }
    }

    private void getMainNengLiangEData() {
        mPresenter.getMainNengLiangEData();
    }

    @Override
    public void getMainNengLiangEDataSuccess(MainNengLiangE entityData) {


    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @SuppressLint("HandlerLeak")
    @Override
    protected void onDestroy() {
        super.onDestroy();

        //如果参数为null的话，会将所有的Callbacks和Messages全部清除掉。
        hanlder.removeCallbacksAndMessages(null);
    }

//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        if (keyCode == KeyEvent.KEYCODE_BACK) {
//            ExitUtil.exit(this);
//            return false;
//        }
//        return super.onKeyDown(keyCode, event);
//    }

    @Override
    protected void onResume() {
        super.onResume();

        if (!TextUtils.isEmpty(mSharedPreferencesHelper.getString(BaseConstants.UID))) {

            new Thread(new Runnable() {

                @Override
                public void run() {

                    try {

                        if (appIndexCount()) {
                            Message m = new Message();
                            m.what = LOGINSUCCESS;
                            hanlder.sendMessage(m);
                        }

                    } catch (Exception e) {
                        Message m = new Message();
                        m.what = SYSERROR;
                        hanlder.sendMessage(m);
                    }

                }
            }).start();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
        if (requestCode == 103) {
            toZhouBaoActivity();
        }
        if (requestCode == 104) {
            toQianDao(RouterHub.ACTIVITY_QIAN_DAO);
        }
    }

    private void toZhouBaoActivity() {
        Intent intent = new Intent(MainNengLiangEActivity.this, ZhouBaoActivity.class);
        startActivity(intent);
    }

    private void toQianDao(String activityQianDao) {
        Utils.navigation(getContext(), activityQianDao);
    }

    private boolean appIndexCount() {
//        LoadingDialogUtil.showGifdialog2(getSupportFragmentManager(), R.drawable.public_loading);

        boolean flag = false;

        try {

            /****************** 调用webService ***********************/
            // 调用.net 的WebService.
            String nameSpace = "http://dyjapp.org/";
            String methodName = "GetAppMainPageCount";

            String url = "http://" + mSharedPreferencesHelper.getString(BaseConstants.IP) + ":"
                    + mSharedPreferencesHelper.getString(BaseConstants.PORT)
                    + "/StoreService.asmx";

            String soapAction = nameSpace + methodName;

            // 设置连接参数
            SoapObject request = new SoapObject(nameSpace, methodName);

            // 增加属性参数。 将相关的函数参数放入到过程中。
            request.addProperty("user_id", mSharedPreferencesHelper.getString(BaseConstants.UID));

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);// soap协议版本必须用SoapEnvelope.VER11（Soap
            // V1.1）;

            // 注意：这个属性是对dotnetwebservice协议的支持,如果dotnet的webservice
            // 不指定rpc方式则用true否则要用false
            envelope.dotNet = true;

            // envelope.setOutputSoapObject(request);//设置请求参数
            envelope.bodyOut = request; // enveloper.bodyOut=request 与
            // envelope.setOutputSoapObject(request)
            // 效果相同。
            // step4 创建HttpTransportSE对象
            HttpTransportSE ht = new HttpTransportSE(url);
            // step5 调用WebService
            ht.call(soapAction, envelope); // 关键的一步，很多问题都在这一步调试时出现问题。要么是IIS有问题，要么是ksoap2相关参数没配置好。
            if (envelope.getResponse() != null) {
                SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                // if ("1".equals(response.toString())) {
                String t = response.toString();

                if (!t.equals("")) {
                    flag = true;
                    Gson gson = new Gson();
                    mAppIndexCount = gson.fromJson(t, AppIndexCount.class);
                }

            }
            /****************** 调用webService结束 ***********************/

        } catch (Exception e) {
            // TODO: handle exception
            LoadingDialogUtil.dismissDialog();
            flag = false;
            SYSException = e.toString();
        }

        return flag;
    }
}
